<?php
namespace app\merchant\controller;

use tp5_lib\user\controller\LoginController as LoginBaseController;
use app\merchant\model\MerchantModel;

class LoginController extends LoginBaseController
{
    protected function loginRedirect($user,$msg="")
    {
        //检查是否绑定手机号
        if(empty($user["mobile"])){
            session("bind_mobile_user_id",$user["id"]);
            $this->redirect("user/login/bindMobile");
        }

        //检查是否提交店铺资料
        $model=new MerchantModel();
        if(!$info=$model->db()->where(["user_id"=>$user["id"]])->find()){
            $this->redirect("auth/index");
        }
        session("merchant_info",$info->toArray());
        if($info["status"] == "0"){
            $this->redirect("auth/wait");
        }
        elseif($info["status"] == "2"){
            $this->redirect("auth/failed");
        }

        $name=static::class.":redirect_url";
        if($url=session($name)){
            session($name,null);
        }
        else{
            $url=url("user/index/index");
        }
        if($msg){
            $this->success($msg,$url);
        }
        else{
            $this->redirect($url);
        }
    }
}
